package org.linlinjava.litemall.admin.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.linlinjava.litemall.db.domain.LitemallAdmin;

public class CommonUtil {
    /**
     * 获取当前登录的账号
     * @return
     */
    public static LitemallAdmin getCurrentAdmin(){
        Subject currentUser = SecurityUtils.getSubject();
        return (LitemallAdmin) currentUser.getPrincipal();
    }
    /**
     * 获取当前登录账号对应商铺ID
     * @return
     */
    public static Long getVendorId(){
        return getCurrentAdmin().getVendorId();
    }

    /**
     * 是否是系统超级管理员
     * @return
     */
    public static boolean isSysAdmin() {
        Subject subject= SecurityUtils.getSubject();
        //有创建用户权限，是超级管理员
        return subject.isPermitted("admin:admin:create");
    }
}
